import * as API from '../../constants/api';
import { getCommonHeaders } from '../../utils/request';
import * as CST from './constants';

export default {
  data () {
    return {
      FILE_UPLOAD_RULE_MSG: CST.FILE_UPLOAD_RULE_MSG,
      ATTENDANCE_IMPORT: API.ATTENDANCE_IMPORT,
      headers: getCommonHeaders(),
    };
  },
  methods: {
    beforeUpload (file) {
      if (file.size < CST.FILE_UPLOAD_SIZE) {
        for (const type of CST.FILE_UPLOAD_TYPES) {
          if (file.type.endsWith(`/${type}`)) {
            this.headers = getCommonHeaders();
            return true;
          }
        }
      }
      this.$message.warning(CST.FILE_UPLOAD_RULE_MSG);
      return false;
    },
  },
}
